﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
#if DOT_NET
using Microsoft.VisualStudio.TestTools.UnitTesting;
#else
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
#endif
using StyleMVVM.DependencyInjection;
using StyleMVVM.Messenger;
using StyleMVVM.UnitTests.TestClasses.SimpleObjects;

namespace StyleMVVM.UnitTests.Messenger
{
	[TestClass]
	public class DispatchedMessengerTests : BaseTestClass
	{
		[TestMethod]
		public void SendTest()
		{
			DispatchedMessenger messenger = new DispatchedMessenger();

			bool received = false;

			messenger.Register<int>((x) => received = true);

			messenger.Send(5);

			Assert.IsTrue(received);
		}

		[TestMethod]
		public void AutoRegistrationTest()
		{
			DispatchedMessageHandlerObject objectHandler =
				Container.Locate<DispatchedMessageHandlerObject>();

			int testValue = 42;

			Container.Locate<IDispatchedMessenger>().Send(
				new SimpleType { TestInt = testValue });

			Assert.AreEqual(testValue, objectHandler.TestInt);
		}
	}
}